package com.xizi.秋招笔试;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-19下午 07:33
 */
public class Test3 {
    public static void main(String[] args) {
        String s = printMaxChar("aaaadsfsdfddddsfsaaaad");
        System.out.println(s);
    }

    public static String printMaxChar(String str) {
        int[] res = new int[26];
        for (int i = 0; i < str.length(); ) {
            char tmp = str.charAt(i);
            int count = 1;
            if (i < str.length() - 1 && tmp != str.charAt(i + 1)) {
                res[tmp - 'a'] = count;
                i++;
                continue;
            } else {
                while (i < str.length() - 1 && tmp == str.charAt(i + 1)) {
                    count++;
                    i++;
                }
                res[tmp - 'a'] = Math.max(res[tmp - 'a'], count);
            }
            i++;
        }
        StringBuilder sb = new StringBuilder();
        int max = 0;
        for (int i = 0; i < res.length; i++) {
            max = Math.max(max, res[i]);
        }


        for (int i = 0; i < res.length; i++) {
            if (res[i] == max) {
                sb.append((char) (i + 'a'));
                sb.append(";");
            }
        }
        String s = sb.toString();
        int len = s.length();
        return s.substring(0, len - 1);
    }
}
